<?php 
namespace app\sgb\logic;   
use think\Model;

/**
 * Log逻辑定义
 * Class LogLogic
 * @package admin\logic
 */
class NewsLogic extends Model
{
	public $errorMsg=[];   

    /*
     * 获取列表
     */
    public function getList($dataKey = [], $filed = [], $orderby = "status desc,id desc", $page = 1, $pageSize = 5)
    {
        $where = [];

        if (isset($dataKey['status']))
            $where['status'] = intval($dataKey['status']);
 
        if (isset($dataKey['user_id']) && !empty($dataKey['user_id']))
            $where['user_id'] = intval($dataKey['user_id']);

        if (isset($dataKey['circle_id']) && !empty($dataKey['circle_id']))
            $where['circle_id'] = intval($dataKey['circle_id']);


        if (isset($dataKey['key']) && !empty($dataKey['key']))
            $where['title'] = array('like', '%' . $dataKey['key'] . '%');

        if (isset($dataKey['category']) && !empty($dataKey['category'])) {
            if (is_array($dataKey['category']))
                $where['category_id'] = array('in', implode(',', $dataKey['category']));
            else
                $where['category_id'] = intval($dataKey['category']);
        }
        if (isset($dataKey['video_url']) && !empty($dataKey['video_url']))
            $where['video_url'] = $dataKey['video_url'];

        if (isset($dataKey['noid']) && !empty($dataKey['noid']))
            $where['id'] = array('<>', intval($dataKey['noid']));

        return db('news')->where($where)->field($filed)->order($orderby)->limit(($page - 1) * $pageSize, $pageSize)->select();
    } 
}